﻿//The author of this class is Sike Mullivan(http://www.codeproject.com/Members/Skully1022)
//Licence The Code Project Open License (CPOL) 1.02 (http://www.codeproject.com/info/cpol10.aspx)

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;
using System.ComponentModel;
using System.Windows.Forms;

namespace Org.Eurekaa.DNJ.UI.Common
{
    internal sealed class WindowsFormsEditorServiceHelper : IWindowsFormsEditorService, IServiceProvider
    {
        // Fields
        private ComponentDesigner _componentDesigner;

        // Methods
        public WindowsFormsEditorServiceHelper(ComponentDesigner componentDesigner)
        {
            this._componentDesigner = componentDesigner;
        }

        object IServiceProvider.GetService(Type serviceType)
        {
            if (serviceType == typeof(IWindowsFormsEditorService))
            {
                return this;
            }
            if (this._componentDesigner.Component != null)
            {
                ISite site = this._componentDesigner.Component.Site;
                if (site != null)
                {
                    return site.GetService(serviceType);
                }
            }
            return null;
        }

        void IWindowsFormsEditorService.CloseDropDown()
        {
        }

        void IWindowsFormsEditorService.DropDownControl(Control control)
        {
        }

        DialogResult IWindowsFormsEditorService.ShowDialog(Form dialog)
        {
            return UIServiceHelper.ShowDialog(this, dialog);
        }
    }

}
